/* 
 * File:   simulator.h
 * Author: samik
 *
 * Created on 23 November, 2008, 9:03 PM
 */

#ifndef _SIMULATOR_H
#define	_SIMULATOR_H

#ifdef	__cplusplus
extern "C" {
#endif
    /* Node types */
#define MSS 0
#define MH 1

    /* Scale */
#define TOTAL_NO_MHS 6 //actually (TOTAL_NO_MHS-1) MHs, starting at MH-1
#define TOTAL_NO_MSS 2//MSS-0 and MSS-1

    /* Message size */
#define MSGSZ 100

    /* Message types */
#define COMPT_MSG 0
#define MH_CONNECT 1
#define MH_DISCONNECT 3
#define MSS_CONNECT 2
#define ACK_MSG 4
#define CHKPNT_RQST 5

    /* Event types */
#define COMPUTE 1
#define SEND 2
#define RECEIVE 3

#define RESET		0
#define BRIGHT 		1
#define DIM		2
#define UNDERLINE 	3
#define BLINK		4
#define REVERSE		7
#define HIDDEN		8

#define BLACK 		0
#define RED		1
#define GREEN		2
#define YELLOW		3
#define BLUE		4
#define MAGENTA		5
#define CYAN		6
#define	WHITE		7

    /* Output Message Types */
#define ERROR 0
#define MSG_SENT 1
#define MSG_RCVD 2
#define COMPUTING 3
#define INFO 4
#define IMP_INFO 5
#define NIMP 6

    /* Message structure in MSS */
    typedef struct {
        long qmtype;

        int sender_id;
        int msg_type;
        int dest_id;
        int seq_no;
        char content[MSGSZ];
    } Message;

   /*
    * Structure msgbuf:
    * Message Buffer data structure for the Message Queue.
    */
    typedef struct msgbuf {
        long mtype;
        char mtext[MSGSZ];
    } message_buf;

    /* Receive message from tcp socket */
    int receive_message(int s, Message *msg);
    /*
     * Function: dequeue_message()
     * this is a wrapper function for the msgrcv() function with blocking.
     * The function will be blocked if no msg is available
     */
    int send_message(int s, long mt, long si, long di, long sn, char* c);
    int dequeue_message(int qid, long type, Message *qbuf);

    /* Function: dequeue_message_nowait()
     * Same as dequeue_message() but this function will return -1 if no message
     * of specified type is available. It will not be blocked.
     */
    int dequeue_message_nowait(int qid, long type, Message *qbuf);

    /*
     * Function: enqueue_message()
     * Wrapper function for the msgsnd() function
     */
    int enqueue_message(int qid, Message *qbuf);

    void textcolor(int attr, int fg, int bg);
    void output(char*msg, int type);

#ifdef	__cplusplus
}
#endif

#endif	/* _SIMULATOR_H */

